package com.kaifamiao.month04.day26.work;


import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class FileNum {
    static List<File> pic = new ArrayList<>();
    static String[] pattern = {".jpg", ".jpeg", ".png", ".gif", ".svg", ".bmp"};

    public static void main(String[] args) {
        Long now = System.currentTimeMillis();
        String pos = "E:\\";
        File file = new File(pos);
        List list = init(file);
        if (list != null) {
            entry(list);
        }
//        print(pic);
        System.out.println(System.currentTimeMillis() - now);

    }

    public static List init(File file) {
        File[] ff = file.listFiles();
        List f = new ArrayList();
        if (ff != null) {
            for (File file2 : ff) {
                f.add(file2);
            }
            return f;
        } else {
            return null;
        }
    }

    public static void entry(List<File> list) {
        for (File file2 : list) {
            boolean flag = false;
            for (String end : pattern) {
                if ((!file2.isDirectory()) && file2.getName().endsWith(end)) {
                    pic.add(file2);
                    flag = true;
                    break;
                }
            }
            if (!flag && file2.isDirectory() && !(file2.isHidden())) {
                search(file2);
            }

        }

    }

    public static void search(File file2) {

        List<File> list = init(file2);
        if (list != null) {
            entry(list);
        }

    }

    public static void print(List<File> pic) {
        int count = 0;
        for (File file : pic) {
            System.out.println(file.getName());
            count++;
        }
        System.out.println(count);
    }
}
